﻿<Window x:Class="FloydPink.Flickr.Downloadr.UI.BrowserWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        ResizeMode="NoResize" mc:Ignorable="d"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:controls="clr-namespace:FloydPink.Flickr.Downloadr.UI.Controls"
        xmlns:behaviors="clr-namespace:FloydPink.Flickr.Downloadr.UI.Behaviors"
        xmlns:cachedImage="clr-namespace:CachedImage;assembly=CachedImage"
        d:DesignHeight="500"
        d:DesignWidth="700"
        Title="Photo Browser - flickr downloadr" Icon="/flickr%20downloadr;component/Images/icon.png"
        SizeToContent="Width" Height="600" MinWidth="950"
        WindowStartupLocation="Manual"
        Left="50" Top="50">

    <Window.Resources>
        <DataTemplate x:Key="PhotoListDataTemplate">
            <Grid>
                <Border BorderBrush="Lavender" BorderThickness="1" Width="150" Height="150" Padding="10" Margin="15"
                        CornerRadius="10">
                    <cachedImage:Image ImageUrl="{Binding LargeSquare150X150Url, IsAsync=True}" Stretch="Fill"
                                             HorizontalAlignment="Center">
                        <Image.ToolTip>
                            <Grid>
                                <cachedImage:Image ImageUrl="{Binding Medium500Url, IsAsync=True}" Stretch="Fill"
                                                         HorizontalAlignment="Center" />
                                <AdornerDecorator>
                                    <StackPanel Orientation="Vertical" VerticalAlignment="Bottom">
                                        <TextBlock Text="{Binding Title, IsAsync=True}" HorizontalAlignment="Center"
                                                   Margin="3" FontFamily="Consolas" FontSize="20"
                                                   VerticalAlignment="Bottom"
                                                   Foreground="#FFFFFFFF" Background="#44000000">
                                            <TextBlock.Effect>
                                                <DropShadowEffect />
                                            </TextBlock.Effect>
                                        </TextBlock>
                                    </StackPanel>
                                </AdornerDecorator>
                            </Grid>
                        </Image.ToolTip>
                    </cachedImage:Image>
                </Border>
            </Grid>
        </DataTemplate>
        <ItemsPanelTemplate x:Key="PhotoListItemsPanelTemplate">
            <UniformGrid Columns="5" HorizontalAlignment="Center" VerticalAlignment="Stretch" />
        </ItemsPanelTemplate>
    </Window.Resources>

    <Grid>
        <Grid
            DataContext="{Binding RelativeSource={RelativeSource FindAncestor,AncestorType={x:Type Window}}, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}">
            <Grid.RowDefinitions>
                <RowDefinition Height="*" />
                <RowDefinition Height="40" />
            </Grid.RowDefinitions>
            <ListBox Grid.Row="0" Grid.ColumnSpan="3" x:Name="PagePhotoList" ItemsSource="{Binding}"
                     ItemTemplate="{DynamicResource PhotoListDataTemplate}"
                     ItemsPanel="{DynamicResource PhotoListItemsPanelTemplate}" SelectionMode="Multiple"
                     behaviors:ScrollToTopBehavior.ScrollToTop="True" />
            <Grid Grid.Row="1">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <StackPanel Grid.Column="0" Orientation="Horizontal" HorizontalAlignment="Left">
                    <Button Content="Back" Width="60" Height="28" ToolTip="Go back to previous screen"
                            Margin="5,0,0,0" Click="BackButtonClick" IsCancel="True" />
                    <ToggleButton Name="PublicAllToggleButton" Margin="5,0,0,0" Width="145" Height="28"
                                  Click="TogglePhotosButtonClick">
                        <ToggleButton.Style>
                            <Style TargetType="{x:Type ToggleButton}">
                                <Setter Property="Content" Value="Show All Photos" />
                                <Setter Property="ToolTip" Value="Now showing only public photos" />
                                <Style.Triggers>
                                    <Trigger Property="IsChecked" Value="True">
                                        <Setter Property="Content" Value="Show Only Public Photos" />
                                        <Setter Property="ToolTip"
                                                Value="Now showing all photos including private ones" />
                                        <Setter Property="Foreground" Value="Blue" />
                                    </Trigger>
                                </Style.Triggers>
                            </Style>
                        </ToggleButton.Style>
                    </ToggleButton>
                    <Button Content="R" Height="28" ToolTip="Select all photos on this page"
                            Margin="20,0,0,0" Click="SelectAllButtonClick" FontFamily="Wingdings 2" FontSize="24"
                            IsEnabled="{Binding Path=AreAllPagePhotosSelected}" />
                    <Button Content="Q" Height="28" ToolTip="Deselect all photos on this page"
                            Margin="5,0,0,0" Click="DeselectAllButtonClick" FontFamily="Wingdings 2" FontSize="24"
                            IsEnabled="{Binding Path=AreAnyPagePhotosSelected}" />
                </StackPanel>
                <StackPanel Grid.Column="1" Orientation="Horizontal" HorizontalAlignment="Center">
                    <Button Content="l&lt;&lt;" ToolTip="Go to first page"
                            Width="30" Height="28" Margin="5,0" Click="FirstPageButtonClick" />
                    <Button Content="&lt;" ToolTip="Go to previous page"
                            Width="25" Height="28" Margin="5,0" Click="PreviousPageButtonClick" />
                    <Grid>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <StackPanel Orientation="Horizontal" Grid.Row="0" HorizontalAlignment="Center">
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center"
                                       Text="{Binding Path=FirstPhoto}" />
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center">-</TextBlock>
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center"
                                       Text="{Binding Path=LastPhoto}" />
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center">of</TextBlock>
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center"
                                       Text="{Binding Path=Total}" />
                            <TextBlock Margin="5,0" Foreground="DimGray" VerticalAlignment="Center">Photos</TextBlock>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal" Grid.Row="1" HorizontalAlignment="Center">
                            <TextBlock Margin="5,0" VerticalAlignment="Center" Text="{Binding Path=Page}" />
                            <TextBlock Margin="5,0" VerticalAlignment="Center">of</TextBlock>
                            <TextBlock Margin="5,0" VerticalAlignment="Center" Text="{Binding Path=Pages}" />
                            <TextBlock Margin="5,0" VerticalAlignment="Center">Pages</TextBlock>
                        </StackPanel>
                    </Grid>
                    <Button Content="&gt;" ToolTip="Go to next page"
                            Width="25" Height="28" Margin="5,0" Click="NextPageButtonClick" />
                    <Button Content="&gt;&gt;l" ToolTip="Go to last page"
                            Width="30" Height="28" Margin="5,0" Click="LastPageButtonClick" />
                </StackPanel>
                <StackPanel Grid.Column="2" Orientation="Horizontal" HorizontalAlignment="Right">
                    <TextBlock VerticalAlignment="Center" HorizontalAlignment="Center" Margin="5,0" FontSize="14"
                               FontWeight="Bold">
                        Download
                    </TextBlock>
                    <Button Content="{Binding Path=SelectedPhotosCountText}" Height="28"
                            ToolTip="Download selected photos"
                            Margin="0,0,5,0" Click="DownloadSelectionButtonClick" Width="95"
                            IsEnabled="{Binding Path=SelectedPhotosExist}" />
                    <Button Content="This Page" Height="28" ToolTip="Download all the photos on this page"
                            Margin="0,0,5,0" Click="DownloadThisPageButtonClick" Width="60" />
                    <Button Content="All Pages" Height="28" ToolTip="Download all the photos"
                            Margin="0,6,5,6" Click="DownloadAllPagesButtonClick" Width="60" />
                </StackPanel>
                <Grid.Background>
                    <SolidColorBrush Color="Gainsboro" Opacity="0.7" />
                </Grid.Background>
                <Grid.Effect>
                    <DropShadowEffect BlurRadius="25" Direction="90" ShadowDepth="3"
                                      RenderingBias="Performance" Opacity="0.2" Color="Olive" />
                </Grid.Effect>
            </Grid>
        </Grid>
        <AdornerDecorator Name="Spinner" Visibility="Collapsed">
            <controls:Spinner x:Name="SpinnerInner" />
        </AdornerDecorator>
    </Grid>
</Window>